<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对象基础</title>
    <script>
      // 创建对象
      var UserObj = {
        name: "dong", // 属性
        do: function (str) {
          // 方法内获取属性
          console.log(str + this.name);
        }, // 方法
        info: function () {
          console.log(this.name, this.age, this.address);
        },
      };
      UserObj.do("I love you ");

      // 设置对象属性值
      UserObj.age = 10;
      UserObj["address"] = "Beijing";
      UserObj.info();

      // 创建类
      function User(name, age) {
        this.name = name;
        this.age = age;
        this.info = function () {
          console.log(this.name, this.age);
        };
      }

      // 创建对象 (方式一)
      let u1 = new User("xixi", 100);
      u1.info();

      // 创建对象（方式二, 基于现有对象创建）
      let u2 = Object.create(u1);
      u2.name = "nannan";
      u2.age = 200;
      u2.info();
    </script>
  </head>
  <body></body>
</html>
